window.onload = function () {
    cutByItem(1);
}

function cutByItem(pageNO) {
    axios.get("/theme/findById").then(resp => {
        let info = resp.data;
        $("channelSpan").innerHTML = info.name;
    })
    axios.get("/theme/cutByItem", {
        params: {
            pageNO: pageNO,
            title: $("title").value,
            name: $("name").value,
            startDate: $("startDate").value,
            endDate: $("endDate").value
        }
    }).then(resp => {
        let info = resp.data;
        let str = "";
        info.records.forEach(n => {
            str += `<tr><td><a href="javascript:setThemeId(${n.id})">${n.title}</a></td><td>${n.user.name}</td>
                    <td>${n.replyNum}</td><td>${n.date}</td></tr>`
        })
        $("data").innerHTML = str;
        let page = "";
        for (let i = 1; i <= info.pages; i++) {
            page += `<a style="margin-left: 10px" href="javascript:cutByItem(${i})">${i}</a>`
        }
        $("pageDiv").innerHTML = page;
    })
}

function addTheme() {
    location.href = "/forum/add.html";
}

function setThemeId(themeId) {
    axios.get("/theme/setThemeId", {
        params: {
            themeId: themeId
        }
    }).then(resp => {
        if (resp.data == "ok") {
            location.href = "/forum/reply.html";
        }
    })
}